package com.kaifamiao.format;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;

public class NumberFormatTest {

    public static void main(String[] args) throws ParseException {

        NumberFormat nfa = new DecimalFormat( "0000" );

        // 数字格式化
        System.out.println( nfa.format( 1 ) );
        System.out.println( nfa.format( 9 ) );
        System.out.println( nfa.format( 56 ) );
        System.out.println( nfa.format( 123 ) );
        System.out.println( nfa.format( 4567 ) );
        System.out.println( nfa.format( 45678 ) );

        // 解析字符串为数字
        String s = "16,000.00";
        NumberFormat nfb = new DecimalFormat( "##,###.##");
        Number num = nfb.parse( s );
        System.out.println( num );

        int salary = num.intValue();
        System.out.println( salary );

    }

}
